/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package WeatherSystemMain;

import CommonValue.CommonString;
import CommonValue.NetConfig;
import CommonValue.SystemSign;
import DTO.ControlDTO;
import SensorCheckersImpl.HumiditySensorChecker;
import SensorCheckersImpl.PressureSensorChecker;
import SensorCheckersImpl.TemperatureSensorChecker;
import SensorCheckersImpl.WindSensorChecker;
import DTO.PacketDTO;
import SocketBusiness.SlaveObeyBoss;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class WeatherSystemMain  {
    
    private static final String systemName = SystemSign.WeatherSystem;

    public static void main(String[] args) {
        System.out.println(systemName+CommonString.MainProgram);
        
        PacketDTO _dataToAC = new PacketDTO(systemName);
        PacketDTO _triggerToAS = new PacketDTO(systemName);
        ControlDTO _operationWS = new ControlDTO(SystemSign.AdminCenter, systemName);

        CheckWeatherBoundary WS_listen_Sensor = new CheckWeatherBoundary(systemName, NetConfig.WeaSys_Listen_SenMan_Port,_operationWS,_dataToAC,_triggerToAS);
        WS_listen_Sensor.installNewSensorChecker(new PressureSensorChecker());
        WS_listen_Sensor.installNewSensorChecker(new TemperatureSensorChecker());
        WS_listen_Sensor.installNewSensorChecker(new WindSensorChecker());        
        WS_listen_Sensor.installNewSensorChecker(new HumiditySensorChecker());        
        Thread t1 = new Thread(WS_listen_Sensor, systemName+CommonString.ThreadName+1);
        t1.start();
        
        DataToAC WS_report_AC = new DataToAC(systemName,NetConfig.AdminCenterIP, NetConfig.AdmCen_Listen_WeaSys_Port,_operationWS,_dataToAC);
        Thread t2 = new Thread(WS_report_AC, systemName+CommonString.ThreadName+2);
        t2.start();
        
        TriggerToAS WS_trigger_AS = new TriggerToAS(systemName,NetConfig.AlarmSystemIP, NetConfig.AlaSys_Listen_WeaSys_Port,_operationWS,_triggerToAS);
        Thread t3 = new Thread(WS_trigger_AS, systemName+CommonString.ThreadName+3);
        t3.start();
        
        SlaveObeyBoss WS_Obey_AC = new SlaveObeyBoss(systemName, NetConfig.AdmCen_Control_WeaSys_Port, _operationWS);
        Thread t4 = new Thread(WS_Obey_AC,systemName+CommonString.ThreadName+4);
        t4.start();
        
        for(;;){//test control he thong
            System.out.println(">>>>>>>>>>>>>>>>>"+systemName + (_operationWS.getFlag() ? " ON " : " OFF "));
            try {
                Thread.sleep(3000);
            } catch (InterruptedException ex) {
                Logger.getLogger(WeatherSystemMain.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }
        
    }
}
